package com.tudouji.project.store.service.impl;

import java.util.List;

import com.tudouji.common.utils.DateUtils;
import com.tudouji.common.utils.IdUtils;
import com.tudouji.common.utils.SecurityUtils;
import com.tudouji.common.utils.StringUtils;
import com.tudouji.project.store.domain.Storeroom;
import com.tudouji.project.store.mapper.StoreroomMapper;
import org.apache.commons.beanutils.ConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tudouji.project.store.mapper.StorehouseroomMapper;
import com.tudouji.project.store.domain.Storehouseroom;
import com.tudouji.project.store.service.IStorehouseroomService;

/**
 * 库间管理Service业务层处理
 *
 * @author wf
 * @date 2021-01-04
 */
@Service
public class StorehouseroomServiceImpl implements IStorehouseroomService {
    @Autowired
    private StorehouseroomMapper storehouseroomMapper;
    @Autowired
    private StoreroomMapper storeroomMapper;

    /**
     * 查询库间管理
     *
     * @param guid 库间管理ID
     * @return 库间管理
     */
    @Override
    public Storehouseroom selectStorehouseroomById(String guid) {
        return storehouseroomMapper.selectStorehouseroomById(guid);
    }

    /**
     * 查询库间管理列表
     *
     * @param storehouseroom 库间管理
     * @return 库间管理
     */
    @Override
    public List<Storehouseroom> selectStorehouseroomList(Storehouseroom storehouseroom) {
        return storehouseroomMapper.selectStorehouseroomList(storehouseroom);
    }

    /**
     * 新增库间管理
     *
     * @param storehouseroom 库间管理
     * @return 结果
     */
    @Override
    public int insertStorehouseroom(Storehouseroom storehouseroom) {
        storehouseroom.setGuid(IdUtils.fastSimpleUUID());
        storehouseroom.setCreatedate(DateUtils.getNowDate());
        storehouseroom.setOperatorid(SecurityUtils.getLoginUser().getUser().getUserId().toString());
        storehouseroom.setLastupdate(DateUtils.getNowDate());
        return storehouseroomMapper.insertStorehouseroom(storehouseroom);
    }

    /**
     * 修改库间管理
     *
     * @param storehouseroom 库间管理
     * @return 结果
     */
    @Override
    public int updateStorehouseroom(Storehouseroom storehouseroom) {
        storehouseroom.setLastupdate(DateUtils.getNowDate());
        return storehouseroomMapper.updateStorehouseroom(storehouseroom);
    }

    /**
     * 批量删除库间管理
     *
     * @param guids 需要删除的库间管理ID
     * @return 结果
     */
    @Override
    public int deleteStorehouseroomByIds(String[] guids) {
        return storehouseroomMapper.deleteStorehouseroomByIds(guids);
    }

    /**
     * 删除库间管理信息
     *
     * @param guid 库间管理ID
     * @return 结果
     */
    @Override
    public int deleteStorehouseroomById(String guid) {
        return storehouseroomMapper.deleteStorehouseroomById(guid);
    }

    /**
     * 校验是否可以删除库房和库间
     *
     * @param storehouseroom
     * @return
     */
    public Integer checkDeleteStore(Storehouseroom storehouseroom) {
        return this.storehouseroomMapper.checkDeleteStore(storehouseroom);
    }

    @Override
    public List<Storehouseroom> getStoreHouseRoomByRoomId(Long id, Integer type, String stats) {

        Storeroom storeroom = storeroomMapper.selectStoreroomById(id);
        Storehouseroom storehouseroom = new Storehouseroom();

        storehouseroom.setStoreguid(storeroom.getGuid());
        storehouseroom.setStatus(stats);
        if (StringUtils.isBlank(stats)) {
            storehouseroom.setStatus("1");
        }
        storehouseroom.setShrtype(type);
        return storehouseroomMapper.selectStorehouseroomList(storehouseroom);
    }

    @Override
    public Storehouseroom selectSHbySotreIdAndType(String srguid, Integer type) {
        Storehouseroom room=new Storehouseroom();
        room.setStoreguid(srguid);
        room.setShrtype(type);
        return storehouseroomMapper.selectSHbySotreIdAndType(room);
    }
}
